package bdd.standalone.bean;

import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import enumTypes.LogType;

/**
 * Bean Log.
 * @author Guillaume Pocas & Jean-Fraçois Augé
 */
@Entity
@Table(name = "log")
public class Log {

	@Id
	@GeneratedValue
	@Column(name = "log_id")
	private int log_id;
	
	@Column(name = "log_date", nullable = false, updatable = false)
	private Date log_date;
	
	@Enumerated(EnumType.STRING)
	@Column(name = "log_type", nullable = false, updatable = false)
	private LogType log_type;
	
	@Column(name = "log_machine", nullable = false, updatable = false)
	private String log_machine;
	
	@Column(name = "log_app", nullable = false, updatable = false)
	private String log_app;
	
	@Column(name = "log_message", nullable = false, updatable = false)
	private String log_message;
	
	/*@ManyToOne
    @JoinColumn(name = "user_id")
	@Where(clause = "log_type = Alert")
	private User user;*/

	//@ManyToMany(mappedBy="alerts")
    //private Set<User> users = new HashSet<User>();
	
	@OneToMany(mappedBy="log")
    private Set<User_Log> user_logs;
	
	/**
	 * Constructeur vide.
	 */
	public Log() {}
 
	/**
	 * Créer un nouveau Log.
	 * @param date
	 * @param type
	 * @param machine
	 * @param app
	 * @param message
	 */
	public Log(Date date, LogType type, String machine, String app, String message) {
		this.log_date = date;
		this.log_type = type;
		this.log_machine = machine;
		this.log_app = app;
		this.log_message = message;
	}

	public int getLog_id() { return log_id; }
	public void setLog_id(int log_id) { this.log_id = log_id; }

	public Date getLog_date() { return log_date; }
	public void setLog_date(Date log_date) { this.log_date = log_date; }

	public LogType getLog_type() { return log_type; }
	public void setLog_type(LogType log_type) { this.log_type = log_type; }

	public String getLog_machine() { return log_machine; }
	public void setLog_machine(String log_machine) { this.log_machine = log_machine; }

	public String getLog_app() { return log_app; }
	public void setLog_app(String log_app) { this.log_app = log_app; }

	public String getLog_message() { return log_message; }
	public void setLog_message(String log_message) { this.log_message = log_message; }
	
	public Set<User_Log> getUser_logs() { return user_logs; }
	public void setUser_logs(Set<User_Log> user_logs) { this.user_logs = user_logs; }

	@Override
	public String toString() { return this.log_message; }
	
}
